#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        if(prices.size() <= 1){
            return 0;
        }
        int pre = prices[0];
        int ans = 0;
        for (int i = 1; i < prices.size(); i++){
            // out
            ans = max(ans, prices[i] - pre);
            // in
            pre = min(pre, prices[i]);
        }
        return ans;
    }
};
